home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) import sys import logging import subprocess import apt import os from DistUpgradeView import DistUpgradeView, InstallProgress, FetchProgress import apt.progress as apt import gettext from DistUpgradeGettext import gettext as _ def wrap(t, width = 70, subsequent_indent = ''): out = '' for s in t.split(): if (len(out) - out.rfind('\n')) + len(s) > width: out += '\n' + subsequent_indent out += s + ' ' return out def twrap(s, **kwargs): msg = '' paras = s.split('\n') for par in paras: s = wrap(par, **kwargs) msg += s + '\n' return msg class TextFetchProgress(FetchProgress, apt.progress.TextFetchProgress): def __init__(self): apt.progress.TextFetchProgress.__init__(self) FetchProgress.__init__(self) def pulse(self): apt.progress.TextFetchProgress.pulse(self) FetchProgress.pulse(self) return True class TextCdromProgressAdapter(apt.progress.CdromProgress): ''' Report the cdrom add progress ''' def update(self, text, step): ''' update is called regularly so that the gui can be redrawn ''' if text: print '%s (%f)' % (text, (step / float(self.totalSteps)) * 100) def askCdromName(self): return (False, '') def changeCdrom(self): return False class DistUpgradeViewText(DistUpgradeView): ''' text frontend of the distUpgrade tool ''' def __init__(self, datadir = None, logdir = None): if not os.environ.has_key('DEBIAN_FRONTEND'): os.environ['DEBIAN_FRONTEND'] = 'dialog' if not datadir: localedir = os.path.join(os.getcwd(), 'mo') else: localedir = '/usr/share/locale/update-manager' try: gettext.bindtextdomain('update-manager', localedir) gettext.textdomain('update-manager') except Exception: e = None logging.warning('Error setting locales (%s)' % e) self.last_step = 0 self._opCacheProgress = apt.progress.OpTextProgress() self._fetchProgress = TextFetchProgress() self._cdromProgress = TextCdromProgressAdapter() self._installProgress = InstallProgress() sys.excepthook = self._handleException def _handleException(self, type, value, tb): import traceback print lines = traceback.format_exception(type, value, tb) logging.error('not handled exception:\n%s' % '\n'.join(lines)) self.error(_('A fatal error occurred'), _('Please report this as a bug and include the files /var/log/dist-upgrade/main.log and /var/log/dist-upgrade/apt.log in your report. The upgrade is now aborted.\nYour original sources.list was saved in /etc/apt/sources.list.distUpgrade.'), '\n'.join(lines)) sys.exit(1) def getFetchProgress(self): return self._fetchProgress def getInstallProgress(self, cache): self._installProgress._cache = cache return self._installProgress def getOpCacheProgress(self): return self._opCacheProgress def getCdromProgress(self): return self._cdromProgress def updateStatus(self, msg): print print msg sys.stdout.flush() def abort(self): print print _('Aborting') def setStep(self, step): self.last_step = step def showDemotions(self, summary, msg, demotions): self.information(summary, msg, _('Demoted:\n') + twrap(', '.join(demotions))) def information(self, summary, msg, extended_msg = None): print print twrap(summary) print twrap(msg) if extended_msg: print twrap(extended_msg) def error(self, summary, msg, extended_msg = None): print print twrap(summary) print twrap(msg) if extended_msg: print twrap(extended_msg) return False def showInPager(self, output): ''' helper to show output in a pager''' for pager in [ '/usr/bin/sensible-pager', '/bin/more']: if os.path.exists(pager): p = subprocess.Popen([ pager, '-'], stdin = subprocess.PIPE) p.stdin.write(output) p.stdin.close() p.wait() return None print output def confirmChanges(self, summary, changes, downloadSize, actions = None, removal_bold = True): DistUpgradeView.confirmChanges(self, summary, changes, downloadSize, actions) print print twrap(summary) print twrap(self.confirmChangesMessage) print ' %s %s' % (_('Continue [yN] '), _('Details [d]')), while True: res = sys.stdin.readline() if res.strip().lower().startswith(_('y')): return True if res.strip().lower().startswith(_('n')): return False print '%s %s' % (_('Continue [yN] '), _('Details [d]')), continue res.strip().lower().startswith(_('y')) if res.strip().lower().startswith(_('d')) else res.strip().lower().startswith(_('n')) def askYesNoQuestion(self, summary, msg, default = 'No'): print print twrap(summary) print twrap(msg) if default == 'No': print _('Continue [yN] '), res = sys.stdin.readline() if res.strip().lower().startswith(_('y')): return True return False print _('Continue [Yn] '), res = sys.stdin.readline() if res.strip().lower().startswith(_('n')): return False return True def confirmRestart(self): return self.askYesNoQuestion(_('Restart required'), _("To finish the upgrade, a restart is required.\nIf you select 'y' the system will be restarted."), default = 'No') if __name__ == '__main__': view = DistUpgradeViewText() print twrap('89 packages are going to be upgraded.\nYou have to download a total of 82.7M.\nThis download will take about 10 minutes with a 1Mbit DSL connection and about 3 hours 12 minutes with a 56k modem.', subsequent_indent = ' ') view = DistUpgradeViewText() print view.askYesNoQuestion('hello', 'Icecream?', 'No') print view.askYesNoQuestion('hello', 'Icecream?', 'Yes') sys.exit(0) view.confirmRestart() cache = apt.Cache() fp = view.getFetchProgress() ip = view.getInstallProgress(cache) for pkg in sys.argv[1:]: cache[pkg].markInstall() cache.commit(fp, ip) sys.exit(0) view.getTerminal().call([ 'dpkg', '--configure', '-a']) view.error('short', 'long', 'asfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\nasfds afsdj af asdf asdf asf dsa fadsf asdf as fasf sextended\n') view.confirmChanges('xx', [], 100) print view.askYesNoQuestion('hello', 'Icecream?')